<?php 
include '../data/data.php';
include '../data/ip.php';
$user=$_SESSION['user']; //获取到的用户名
$pass=$_SESSION['pass']; //获取到的密码
$gid=$_POST['gid'];  //游戏编号
$type=$_POST['type']; //kmlx
$uid=$_POST['uid']; //授权信息
$date=time();//开通时间
$result= mysql_query("SELECT * FROM user WHERE username='$user' and password='$pass'", $link);  
$row = mysql_fetch_array($result);
$resultc= mysql_query("SELECT * FROM games WHERE id='$gid'", $link);  
$rowc = mysql_fetch_array($resultc);
if($row[gm]=='5'){
$money='0';
}else{
$money=$rowc[money];
}
if($row[id]==''){
	exit(header('location:/user/login.html?fwd=/index.html'));
}
if($_SERVER['REQUEST_URI']!='/game/kt' & $_SERVER['REQUEST_URI']=='/game/kt.php'){
	exit('<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /game/kt.php was not found on this server.</p>
<hr>
<address>Apache Server at www.81im.com Port 80</address>

</body></html>');
}
if($rowc[api]=='0'){
	exit('<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /game/kt.php was not found on this server.</p>
<hr>
<address>Apache Server at www.81im.com Port 80</address>

</body></html>');
}
if($type!='vip'){
    $returndata = array("errcode"=>0,"info"=>"fail");
    exit(json_encode($returndata));
}
if($type=='vip'){
if($row[gm]!='' & $row[gm]!='0'){ //包站会员
$cresult= mysql_query("SELECT * FROM games_vip WHERE user_id='$user' AND game_id='$gid'", $link);   //查询是否开通过
$crow = mysql_fetch_array($cresult); 
if($crow[id]==''){
$ingotsx = "INSERT INTO games_vip (daili_id, user_id, game_id, uid_id, date) VALUES ('$dl', '$user', '$gid', '$uid', '$date')";   //记录
mysql_query($ingotsx, $link);  
$return=array('errcode'=>1,'info'=>'success',);
  exit(json_encode($return)); 
}else{
$return=array('errcode'=>1,'info'=>'您已开通过此游戏，无法重复开通！',);
  exit(json_encode($return)); 
}
}elseif($row['gm']=='0' & $row['gm']!=''){
$umoney=$row['money']; //账户余额
$gmoney=$money; //游戏价格
  if($umoney>$gmoney||$umoney==$gmoney){
  $cresult= mysql_query("SELECT * FROM games_vip WHERE user_id='$user' AND game_id='$gid'", $link);   //查询是否开通过
  $crow = mysql_fetch_array($cresult); 
if($crow[id]==''){
  $ingots = " UPDATE  user  SET   money=$umoney-$gmoney WHERE username='$user' ";   //扣除包站金额
mysql_query($ingots, $link); 
  $ingotsx = "INSERT INTO games_vip (daili_id, user_id, game_id, uid_id, date) VALUES ('$dl', '$user', '$gid', '$uid', '$date')";   //记录
mysql_query($ingotsx, $link);  
  $return=array('errcode'=>1,'info'=>'success',);
  exit(json_encode($return)); 
}else{
$return=array('errcode'=>1,'info'=>'您已开通过此游戏，无法重复开通！'.$rowc[id],);
  exit(json_encode($return)); 
}
  }else{
  $return=array('errcode'=>1,'info'=>'您的平台币余额不足，可用积分兑换平台币哟',);
  exit(json_encode($return)); 
}
}
}
?>